<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>检查接口是否已被定义</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.get-parent-class.html">get_parent_class</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.is-a.html">is_a</a></div>
 <div class="up"><a href="ref.classobj.html">类/对象 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.interface-exists" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">interface_exists</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.0.2)</p><p class="refpurpose"><span class="refname">interface_exists</span> &mdash; <span class="dc-title">检查接口是否已被定义</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.interface-exists-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>interface_exists</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$interface_name</code></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$autoload</code><span class="initializer"> = true</span></span>
  ] )</div>

  <p class="para rdfs-comment">
   检查接口是否已被定义。
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.interface-exists-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">interface_name</code></em></dt>

     <dd>

      <p class="para">
       接口名。
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">autoload</code></em></dt>

     <dd>

      <p class="para">
       默认是否调用 <a href="language.oop5.autoload.html" class="link">__autoload</a>。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.interface-exists-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   本函数在由 <em><code class="parameter">interface_name</code></em>
   给出的接口已定义时返回 <strong><code>TRUE</code></strong>，否则返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.interface-exists-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4960">
    <p><strong>Example #1 <span class="function"><strong>interface_exists()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;在尝试使用前先检查接口是否存在<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">interface_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'MyInterface'</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;class&nbsp;</span><span style="color: #0000BB">MyClass&nbsp;</span><span style="color: #007700">implements&nbsp;</span><span style="color: #0000BB">MyInterface<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Methods<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">}<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.interface-exists-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.get-declared-interfaces.html" class="function" rel="rdfs-seeAlso">get_declared_interfaces()</a> - 返回一个数组包含所有已声明的接口</span></li>
    <li class="member"><span class="function"><a href="function.class-implements.html" class="function" rel="rdfs-seeAlso">class_implements()</a> - 返回指定的类实现的所有接口。</span></li>
    <li class="member"><span class="function"><a href="function.class-exists.html" class="function" rel="rdfs-seeAlso">class_exists()</a> - 检查类是否已定义</span></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.get-parent-class.html">get_parent_class</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.is-a.html">is_a</a></div>
 <div class="up"><a href="ref.classobj.html">类/对象 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
